package com.booking.springrestful.controller;


import com.booking.springrestful.domain.Appointments;
import com.booking.springrestful.domain.Counselors;
import com.booking.springrestful.domain.Useranalytics;
import com.booking.springrestful.domain.Userassessments;
import com.booking.springrestful.domain.dto.AppointmentsDto;
import com.booking.springrestful.domain.dto.BookingDto;
import com.booking.springrestful.domain.dto.GetCouByUserIdDto;
import com.booking.springrestful.domain.vo.AppointmentRecordVo;
import com.booking.springrestful.domain.vo.AppointmentVo;
import com.booking.springrestful.domain.vo.BookingVo;
import com.booking.springrestful.domain.vo.FeedbackVo;
import com.booking.springrestful.resp.PageResult;
import com.booking.springrestful.resp.ResponseResult;
import com.booking.springrestful.service.AppointmentsService;
import com.booking.springrestful.service.CounselorsService;
import com.booking.springrestful.service.UseranalyticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/appointment")
public class appointmentController {


    @Resource
    private AppointmentsService appointmentsService;

    @Resource
    private UseranalyticsService useranalyticsService;



    //预约
    @PostMapping
    private ResponseResult appointment(@RequestBody AppointmentsDto appointments){

        appointmentsService.appointment(appointments);

        //统计表中增加总次数
        useranalyticsService.addTotal(appointments);
        return ResponseResult.success("预约成功");
    }


    //查询咨询师
    @PostMapping("/listCou")
    private ResponseResult<List<List<AppointmentVo>>> listCou(@RequestBody Counselors counselors){
        List<List<AppointmentVo>> list= appointmentsService.listCou(counselors);
        return ResponseResult.success(list);
    }


    @PostMapping("/getByUserId")
    private ResponseResult<PageResult<AppointmentRecordVo>> getByUserId(@RequestBody GetCouByUserIdDto getCouByUserIdDto){
        PageResult<AppointmentRecordVo> byUserId = appointmentsService.getByUserId(getCouByUserIdDto);
        return ResponseResult.success(byUserId);
    }

    //取消预约
    @PostMapping("/cancel")
    private ResponseResult cancel(@RequestBody AppointmentRecordVo appointmentRecordVo){
        appointmentsService.cancel(appointmentRecordVo);

        //统计表中增加取消次数
        useranalyticsService.addCancel(appointmentRecordVo);
        return ResponseResult.success("取消成功");
    }

    @PostMapping("/complete")
    private ResponseResult complete(@RequestBody AppointmentRecordVo appointmentRecordVo){
        appointmentsService.complete(appointmentRecordVo);

        //统计表中增加完成次数
        useranalyticsService.addComplete(appointmentRecordVo);
        return ResponseResult.success("已完成！");
    }

    @PostMapping("/getCouByUserId")
    private ResponseResult<PageResult<AppointmentRecordVo>> getCouByUserId(@RequestBody GetCouByUserIdDto getCouByUserIdDto){
        log.info(getCouByUserIdDto.toString());
        PageResult<AppointmentRecordVo> byUserId = appointmentsService.getCouByUserId(getCouByUserIdDto);
        return ResponseResult.success(byUserId);
    }


    @GetMapping("/getAssess")
    private ResponseResult<Userassessments> getAssess(Integer id){
        Userassessments byId = appointmentsService.getAssess(id);
        return ResponseResult.success(byId);
    }


    //管理端获取预约记录
    @PostMapping("/getBooking")
    private ResponseResult<PageResult<BookingVo>> getBooking(@RequestBody BookingDto bookingDto){
        PageResult<BookingVo> page= appointmentsService.getBooking(bookingDto);
        return ResponseResult.success(page);
    }

    @GetMapping("/getAllRecord")
    private ResponseResult<Boolean> getAllRecord(Integer userid){
        Boolean flag= appointmentsService.getAllRecord(userid);
        return ResponseResult.success(flag);
    }


}
